package com.example.demo.service.impl;

import com.example.demo.entity.Product;
import com.example.demo.model.TableData;
import com.example.demo.repository.ProductRepository;
import com.example.demo.service.TableDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class DatabaseTableDataService implements TableDataService {

    @Autowired
    private ProductRepository productRepository;

    @Override
    public List<TableData> getTableData() {
        List<Product> products = productRepository.findAll();
        
        return products.stream()
                .map(product -> new TableData(
                        product.getId(),
                        product.getName(),
                        product.getType(),
                        product.getPrice(),
                        product.getDate()
                ))
                .collect(Collectors.toList());
    }
}    